<!DOCTYPE html>
<html >
<head>
    <meta charset="utf-8">
    <title> JVM监控 系统线程信息 </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/monitor.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<blockquote class="layui-elem-quote layui-text font16">
   JVM 进程线程信息
</blockquote>
<div class="layui-fluid" id="renderContent">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">总览</li>
            <li >50 TOP BUSY</li>
            <li >50 TOP BLOCK</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <blockquote class="layui-elem-quote" id="showOutlineContent"></blockquote>
                    </div>
                    <div class="layui-card-body">
                        <table class="layui-hide" id="overviewThread" lay-even="" lay-skin="nob"></table>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item ">
                <pre class="layui-code" id="showBusyContent" >

                </pre>
            </div>
            <div class="layui-tab-item ">
                 <pre class="layui-code" id="showBlockContent" >
                </pre>
            </div>
        </div>
    </div>
</div>
<script src="../js/jquery-3.4.0.min.js" charset="utf-8"></script>
<script src="../js/monitor.js" charset="utf-8"></script>
<script src="../layui/layui.all.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script type="text/javascript"  >
    var URLS= {
        overview: "../v1/api/thread/overview.json",
        busythread: "../v1/api/thread/busy.json?top=50",
        blockthread: "../v1/api/thread/block.json"
    }

    $(function(){

        // 线程总览图
        _ajax(URLS.overview ,function (data) {
            if(data){
                var totoalHtml = "";
                if(data.total){
                    for(var key in data.total){
                        totoalHtml = totoalHtml + key + ':' + data.total[key] + " ";
                    }
                }
                // 前端渲染
                $("#showOutlineContent").html(totoalHtml);
                // 渲染线程信息
                layui.use(['table','element'], function(){
                    var table = layui.table;
                    //展示已知数据
                    table.render({
                        elem: '#overviewThread'
                        ,cols: [[
                            {field: 'id', title: 'id',width:60,templet: '#threadIdTpl'}
                            ,{field: 'name', title: 'name' ,minWidth:120}
                            ,{field: 'group', title: 'group',minWidth:120}
                            ,{field: 'priority', title: 'priority'}
                            ,{field: 'state', title: 'state',minWidth:120}
                            ,{field: 'cpu', title: '%cpu'}
                            ,{field: 'time', title: 'time'}
                            ,{field: 'interrupted', title: 'interrupted'}
                            ,{field: 'daemon', title: 'daemon'}
                        ]]
                        ,data: data.threadInfos
                        ,skin: 'nob'
                        ,even: true
                    });
                });
            }

        })
        // busy 100 线程
        _ajax(URLS.busythread ,function (data) {
            if(data){
                var html = "";
                // 渲染线程信息
                layui.use(['table','element','code'], function(){
                    for(var i=0,len =data.length;i < len;i++){
                        html = html + data[i] + "<br/>"
                    }
                    $("#showBusyContent").html(html)
                });
            }

        })
        // 阻塞队列
        _ajax(URLS.blockthread ,function (data) {
            if(data){
                // 阻塞队列
                layui.use(['table','element','code'], function(){
                    $("#showBlockContent").html(data)
                });
            }

        })
    });
</script>

<script type="text/html" id="threadIdTpl">
    <a href="../threadDetail.html?id={{d.id}}" class="layui-table-link" target="_blank">{{d.id}}</a>
</script>
</body>
</html>